﻿Public Class ctlRelationships
    Public Event Reload()
    Public Event OpenRelationship(ByVal Id As Integer)
    Private _Filter As FilterEnum
    Public Property Rows As Integer


    Public Enum FilterEnum
        All
        Unknown
        Active
        Terminated
    End Enum

    Public Property Filter As FilterEnum
        Get
            Filter = _Filter
        End Get
        Set(ByVal value As FilterEnum)
            _Filter = value
            RaiseEvent Reload()
        End Set
    End Property

    Public WriteOnly Property DataTable As DataTable

        Set(ByVal value As DataTable)

            grdRelationships.DataSource = value

            Dim sColumn() As String = {"Id", "Row", "Code", "Child",
                                        "Sponsor", "State", "Start", "End"}

            For n As Integer = 0 To grdRelationships.Columns.Count - 1
                grdRelationships.Columns.Item(n).HeaderText = sColumn(n)
            Next

            'grdRelationships.Columns.Item("relationshipId").Visible = False
            'grdRelationships.Columns.Item("Row").Visible = False

        End Set
    End Property


    Public ReadOnly Property SelectedRelationshipId As Integer
        Get
            Dim id As Long
            If Not IsNothing(grdRelationships.CurrentRow) Then
                id = CLng(grdRelationships.CurrentRow.Cells(0).Value)
            End If

            Return (id)
        End Get
    End Property





    Private Sub grdRelationships_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs)

    End Sub

    Private Sub ToolStrip1_ItemClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ToolStripItemClickedEventArgs) Handles ToolStrip1.ItemClicked




    End Sub

    Public Sub Init()
        Dim oDDI As ToolStripItem
        tsdFilter.DropDownItems.Clear()
        oDDI = tsdFilter.DropDownItems.Add("All")
        oDDI.Name = "FilterEnumAll"

        oDDI = tsdFilter.DropDownItems.Add("Active")
        oDDI.Name = "FilterEnumActive"

        oDDI = tsdFilter.DropDownItems.Add("Terminated")
        oDDI.Name = "FilterEnumTerminated"

        oDDI = tsdFilter.DropDownItems.Add("Unknown")
        oDDI.Name = "FilterEnumUnknown"

    End Sub

    Public Sub New()

        ' This call is required by the designer.
        InitializeComponent()

        ' Add any initialization after the InitializeComponent() call.
        Init()
    End Sub

    Private Sub tsdFilter_DropDownItemClicked(ByVal sender As Object, ByVal e As System.Windows.Forms.ToolStripItemClickedEventArgs) Handles tsdFilter.DropDownItemClicked

        Select Case e.ClickedItem.Name

            Case "tsdFilter"

            Case "FilterEnumAll"
                Filter = FilterEnum.All

            Case "FilterEnumActive"
                Filter = FilterEnum.Active

            Case "FilterEnumTerminated"
                Filter = FilterEnum.Terminated

            Case "FilterEnumUnknown"
                Filter = FilterEnum.Unknown

        End Select
    End Sub

    Private Sub tsbRefresh_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tsbRefresh.Click
        RaiseEvent Reload()
    End Sub

    Private Sub btnOpenSelected_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOpenSelected.Click
        If grdRelationships.SelectedRows.Count > 0 Then
            Dim RelationshipId As Integer = CInt(grdRelationships.SelectedRows(0).Cells("relationshipID").Value)
            RaiseEvent OpenRelationship(RelationshipId)
        End If

    End Sub
End Class
